<template>
  <view class="decoration">
    <view class="title">
      <view class="content-title">
        请填店铺网址并提交
      </view>
      <view class="content-English">
        Please fill in the store address and submit
      </view>
    </view>
    <view class="fromSubmit">
      <view class="from-item">
        <view class="item-title">
          <text class="from-item-title">店铺网址</text>
          <text class="from-item-English">/Shop Addres</text>
        </view>
        <input class="uni-input" v-model="formSubmit.shopAddress" placeholder="请输入店铺网址" />
      </view>
      <button type="warn" class="from-button" @click="submit">提交 /Submit</button>
    </view>
    <view class="buttom" v-for="(item, i) in accessList" :key="i">
      <view class="buttom-list">
        <view class="list-list">
          <view class="list-left">
            <view class="list-center">
              <view class="center-top">
                <text class="top-title">店铺网址 {{ i + 1 }}: </text>
                <!-- <text class="top-English">{{ item.english }}</text> -->
              </view>
              <view class="center-buttom">
                <text>{{ item }}</text>
                <!-- <text>余额：100</text> -->
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <tabBar :currentPage="'tabBar5'"></tabBar>
  </view>
</template>

<script>
import tabBar from '@/components/tabBar.vue'

export default {
  components: {
    tabBar
  },
  data() {
    return {
      formSubmit: {
        shopAddress: '',
      },
      accessList: []
    }
  },
  onLoad() {
    this.shopAddress()
  },
  methods: {
    shopAddress() {
      let params = {
        id: uni.getStorageSync('userInfo').id
      }
      this.$api.getUserShopAddress(params).then(res => {
        if (res.success) {
          if (res.rows.companyAddress) {
            let temp = res.rows.companyAddress.split(',')
            temp.forEach(i => {
              if (i !== '') {
                this.accessList.push(i)
              }
            })
          }
        } else {
          uni.showToast({ title: res.msg })
        }
      }).catch(err => {
        console.log('request fail', err)
      })
    },
    submit() {
      if (this.formSubmit.shopAddress === '') {
        uni.showToast({ title: '店铺地址不能为空', icon: 'none' })
        return
      }
      let params = {
        id: uni.getStorageSync('userInfo').id,
        companyAddress: this.formSubmit.shopAddress
      }
      this.$api.AddShopAddress(params).then(res => {
        if (res.success) {
          this.accessList = []
          this.shopAddress()
          uni.showToast({ title: '提交成功', icon: 'success' })
          // 提交成功赋值为空
          Object.keys(this.formSubmit).map(key => this.formSubmit[key] = '')
        } else {
          uni.showToast({ title: res.msg });
        }
      }).catch(err => {
          console.log('request fail', err)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.decoration {
  .title {
    padding: 0 0 30rpx 0;
    background: #F6F6F6;
    .content-title {
      text-align: center;
      font-size: 34rpx;
      font-weight: bold;
      color: #333333;
      padding-top: 30rpx;
    }
    .content-English {
      text-align: center;
      padding: 0 80rpx;
      font-size: 28rpx;
      color: #999999;
    }
  }
  .fromSubmit {
    padding: 40rpx;
    .from-item {
      margin-bottom: 40rpx;
      .item-title {
        margin-bottom: 20rpx;
        .from-item-title {
          font-size: 32rpx;
          font-weight: 500;
          color: #333333;
          margin-right: 20rpx;
        }
        .from-item-English {
          font-size: 28rpx;
          font-weight: 500;
          color: #999999;
        }
      }
      .uni-input {
        background: #F6F6F6;
        border-radius:4px;
      }
      .from-item-textarea {
        background: #F6F6F6;
        width: 100%;
        border-radius:4px;
      }
    }
    .from-button {
      background: $uni-color-base;
    }
  }
  .buttom {
    .buttom-list {
      padding: 20rpx 32rpx;
      .list-list {
        background: #FFFFFF;
        box-shadow: 0 0 16rpx #999;
        border-radius: 20rpx;
        display: flex;
        padding: 20rpx;
        justify-content: space-between;
        .list-left {
          display: flex;
          align-items: center;
          .left-img {
            width: 60rpx;
            height: 60rpx;
            margin-right: 20rpx;
            image {
              width: 100%;
              height: 100%;
            }
          }
          .list-center {
            view {
              line-height: 60rpx;
            }
            .center-top {
              .top-title {
                font-size: 34rpx;
                font-weight: 400;
                color: #333333;
                margin-right: 20rpx;
              }
              .top-English {
                color: #999999;
                font-size: 28rpx;
              }
            }
            .center-buttom {
              text {
                font-size: 28rpx;
                font-weight: 400;
                color: #999999;
                margin-right: 40rpx;
              }
            }
          }
        }
        .list-right {
          display: flex;
          align-items: center;
          image {
            width: 32rpx;
            height: 32rpx;
          }
          .money {
            font-size: 40rpx;
            color: #FA6400;
          }
        }
      }
    }
  }
}
</style>
